package one.bugu.android.demon.ui.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.juefeng.android.framework.common.base.BaseListAdapter;
import com.juefeng.android.framework.common.util.StringUtil;
import one.bugu.android.demon.R;
import one.bugu.android.demon.bean.ShortMessageInfoBean;

/**
 * 短信列表适配
 */
public class ShortMessageInfoAdapter extends BaseListAdapter<ShortMessageInfoBean> {

    private Context context;

    public ShortMessageInfoAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public int getContentLayoutId() {
        return R.layout.item_shortmessageinfo;
    }

    @Override
    public ViewHolder getViewHolder() {
        return new Holder();
    }

    public class Holder implements ViewHolder<ShortMessageInfoBean> {

        /**
         * 短信数量
         */
        private TextView shortMessageNum;

        /**
         * 时间
         */
        private TextView shortMessageTime;

        /**
         * 内容
         */
        private TextView shortMessageTitle;

        /**
         * 图片类型
         */
        private ImageView typeImg;

        @Override
        public void initView(View view) {

            shortMessageNum = view.findViewById(R.id.shortMessageNum);
            shortMessageTime = view.findViewById(R.id.shortMessage_time);
            shortMessageTitle = view.findViewById(R.id.shortMessage_title);
            typeImg = view.findViewById(R.id.shortMessageType_img);
        }

        @SuppressLint("SetTextI18n")
        @Override
        public void initData(ShortMessageInfoBean shortMessageInfoBean) {

            if (!StringUtil.isEmpty(shortMessageInfoBean.getOptTime())) {
                shortMessageTime.setText(shortMessageInfoBean.getOptTime().substring(0, shortMessageInfoBean.getOptTime().indexOf(".")));
            }

            String string = shortMessageInfoBean.getRemark();

            if (shortMessageInfoBean.getOptType().equals("20")) {

                shortMessageTitle.setText("新用户赠送");
                shortMessageNum.setText("+" + shortMessageInfoBean.getNum());
                typeImg.setImageResource(R.mipmap.yuyin_zengsong);
                shortMessageNum.setTextColor(Color.parseColor("#333333"));

            } else if (shortMessageInfoBean.getOptType().equals("10")) {

                shortMessageTitle.setText("购买");
                shortMessageNum.setText("+" + shortMessageInfoBean.getNum());
                typeImg.setImageResource(R.mipmap.yuyin_chongzhi);
                shortMessageNum.setTextColor(Color.parseColor("#333333"));

            } else if (shortMessageInfoBean.getOptType().equals("40")) {

                shortMessageTitle.setText("使用扣除");
                shortMessageNum.setText("-" + shortMessageInfoBean.getNum());
                typeImg.setImageResource(R.mipmap.yuyin_kouchu);
                shortMessageNum.setTextColor(Color.parseColor("#FE7361"));

            } else if (shortMessageInfoBean.getOptType().equals("30")) {

                shortMessageTitle.setText("邀请奖励");
                shortMessageNum.setText("+" + shortMessageInfoBean.getNum());
                typeImg.setImageResource(R.mipmap.yuyin_yaoqing);
                shortMessageNum.setTextColor(Color.parseColor("#333333"));

            } else if (shortMessageInfoBean.getOptType().equals("50")) {

                shortMessageTitle.setText("返还");
                shortMessageNum.setText("+" + shortMessageInfoBean.getNum());
                typeImg.setImageResource(R.mipmap.yuyin_fanhuan);
                shortMessageNum.setTextColor(Color.parseColor("#333333"));

            }else if ("80".equals(shortMessageInfoBean.getOptType())) {
                shortMessageNum.setTextColor(Color.parseColor("#333333"));
                shortMessageTitle.setText(shortMessageInfoBean.getRemark());
                shortMessageNum.setText("+" + shortMessageInfoBean.getNum());
                typeImg.setImageResource(R.mipmap.bgt_duihuan_d);
            }
        }

        @Override
        public void initEvent(ShortMessageInfoBean shortMessageInfoBean) {

        }
    }
}

